﻿using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;

namespace NBlog.Web.Application.Infrastructure
{
    public static class HtmlExtensions
    {
        public static IHtmlString Raw(this HtmlHelper htmlHelper, string html)
        {
            return MvcHtmlString.Create(html);
        }

        public static IHtmlString Concat(this HtmlHelper htmlHelper, params IHtmlString[] strings)
        {
            var concat = string.Join<IHtmlString>("", strings);
            return MvcHtmlString.Create(concat);
        }

        public static IHtmlString Blank(this HtmlHelper htmlHelper)
        {
            return MvcHtmlString.Empty;
        }

        public static IHtmlString ActionNofollowLink(this HtmlHelper htmlHelper, string linkText, string actionName)
        {
            return htmlHelper.ActionNofollowLink(linkText, actionName, "Home");
        }

        public static IHtmlString ActionNofollowLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName)
        {
            return htmlHelper.ActionLink(linkText, actionName, controllerName, null, new { rel = "nofollow" });
        }

        public static IHtmlString ActionArticleLink(this HtmlHelper htmlHelper, string linkText, string slug)
        {
            return htmlHelper.ActionLink(linkText, "Show", "Entry", new {id = slug}, new {});
        }

        public static IHtmlString ActionArticleLink(this HtmlHelper htmlHelper, string linkText, string slug, string htmlTitle)
        {
            return htmlHelper.ActionLink(linkText, "Show", "Entry", new {id = slug}, new {title = htmlTitle});
        }

        public static MvcHtmlString ShowAds(this HtmlHelper htmlHelper, string partialViewName, HttpRequestBase request)
        {
            if (!request.Headers["HOST"].Contains(".local"))
            {
                return htmlHelper.Partial(partialViewName);
            }

            return MvcHtmlString.Empty;
        }
    }
}